﻿using Microsoft.AspNetCore.Mvc;
using Project.Ycm20250401.Service;
using Project.Ycm20250401.Service._20250407;

namespace Project.Ycm20250401.Net.Controllers
{
    [ApiController]
    [Route("/api/[controller]/[action]")]
    public class CabinetController : ControllerBase
    {
        private readonly CabinetService _service;
        private readonly OrderService _orderService;

        public CabinetController(CabinetService service, OrderService orderService) { 
            _service = service; 
            _orderService = orderService;
            }

        [HttpPost]
        public async Task<IActionResult> OpenDoor([FromBody] CabinetRequest request)
        {
            await _service.OperateCabinet(request.CabinetType, request.CabinetId,
                cabinet => cabinet.OpenDoorAsync(request.CabinetId));
            return Ok();
        }

        /// <summary>
        /// 测试20250407
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<string> Test20250407()
        {
            // 创建满减活动（满200减50）
            var activity = new Activity(
                ActivityType.FullReduction,
                Discount: 0,
                FullAmount: 200,
                Reduction: 50
            );
            var order = new Order(OriginalPrice: 250);
            await _orderService.SubmitOrderAsync(order, activity);
            return activity.Type.ToString();
        }


    }
    public class CabinetRequest
    {
        public string CabinetType { get; set; }
        public int CabinetId { get; set; }
    }
}
